﻿using Admin.Roles;
using Admin.Service.Roles;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Admin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleController : ControllerBase
    {
        private readonly IRoleService roleService;

        public RoleController(IRoleService roleService)
        {
            this.roleService = roleService;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Create(Role role)
        {
            return Ok(roleService.Create(role));
        }

        /// <summary>
        /// 删除 单删
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Delete(int id)
        {
            return Ok(roleService.Delete(id));
        }

        /// <summary>
        /// 删除 批删
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult DeleteList(int[] ids)
        {
            return Ok(roleService.DeleteList(ids));
        }

        /// <summary>
        /// 根据id查询一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetRoleId(int id)
        {
            return Ok(roleService.GetRoleId(id));
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult Update(Role role)
        {
            return Ok(roleService.Update(role));
        }

        /// <summary>
        /// 查询角色信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetRole(string rolename)
        {
            return Ok(roleService.GetRoles(rolename));
        }
    }
}
